using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using 系统中间件.Models;

namespace 系统中间件.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        //启动时会把IWebHostEnvironment接口加入到IOC容器中
        /// <summary>
        /// 
        /// </summary>
        private readonly IWebHostEnvironment _webHostEnvironment;//此接口可以拿到静态文件的根目录

        public HomeController(ILogger<HomeController> logger, IWebHostEnvironment webHostEnvironment)
        {
            _logger = logger;
            _webHostEnvironment = webHostEnvironment;
        }

        public IActionResult Index()
        {

            var aa = new
            {
                WebRootPath = _webHostEnvironment.WebRootPath,//静态文件根目录
                ContentRootPath = _webHostEnvironment.ContentRootPath//项目根目录
            };

            return Ok(aa);
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
